<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header">
	<th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-inventoryPrice-add">
			<input id="inventoryId" name="inventoryId" th:value="*{inventoryId}"  type="hidden">
			<div class="form-group">
				<label class="col-sm-3 control-label">规格名称：</label>
				<div class="col-sm-8">
					<select id="sizeId" name="sizeId" class="form-control" onchange="selectOnChang()">
						<option value="">请选择规格</option>
						<option th:each="inventorySize:${inventorySizeList}" th:value="${inventorySize.sizeId}" th:text="${inventorySize.sizeTitle}"></option>
					</select>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">规格值：</label>
				<div class="col-sm-8">
					<select id="priceId" name="priceId" class="form-control"></select>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">入库数量：</label>
				<div class="col-sm-8">
					<input id="itemNum" name="itemNum" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">价格：</label>
				<div class="col-sm-8">
					<input id="itemSum" name="itemSum" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">备注：</label>
				<div class="col-sm-8">
					<textarea id="remark" name="remark" class="form-control" type="text"></textarea>
				</div>
			</div>
		</form>
	</div>
    <div th:include="include::footer"></div>
	<th:block th:include="include :: select2-js" />
    <script type="text/javascript">
		var prefix = ctx + "business/inventoryPrice"
		$("#form-inventoryPrice-add").validate({
			rules:{
				xxxx:{
					required:true,
				},
			}
		});

		function selectOnChang(){
			//获取被选中的option标签选项
			var sizeId = $.form.selectSelects("sizeId");
			$.ajax({
				type: "POST",
				url: ctx + "business/inventorySizePrice/list",
				data: {
					"sizeId": sizeId
				},
				success: function(result) {
					if (result.code == web_status.SUCCESS) {
						let html = `<option value="">请选择规格</option>`;
						result.data.rows.filter(item=>{
							html += `<option value="${item.priceId}">${item.priceInfo}</option>`;
						});
						$("#priceId").html(html);
					}else {
						$.modal.msgError(result.msg);
					}
				}
			});
		}



		function submitHandler() {
	        if ($.validate.form()) {
				var sizeId = $.form.selectSelects("sizeId");
				if (sizeId == "" || sizeId == null || sizeId == undefined){
					$.modal.msgError("请选择规格");
					return;
				}
				var priceId = $.form.selectSelects("priceId");
				if (priceId == "" || priceId == null || priceId == undefined){
					$.modal.msgError("请选择规格值");
					return;
				}
	            $.operate.save(prefix + "/add", $('#form-inventoryPrice-add').serialize());
	        }
	    }
	</script>
</body>
</html>
